import axios from 'axios';
import { Message } from 'element-ui';

axios.defaults.timeout = 5000;
// axios.defaults.baseURL =process.env.elec;


axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8';



//http request 拦截器
axios.interceptors.request.use(
  config => {

    return config;
  },
  error => {
    return Promise.reject(err);
  }
);


//http response 拦截器
axios.interceptors.response.use(
  response => {
    return response;
  },
  error => {
    return Promise.reject(error)
  }
)


/**
 * 封装get方法
 */

export function get(url,params={}){
  return new Promise((resolve,reject) => {
    axios.get(process.env.elec+url,{
      params:params
    })
    .then(response => {
      resolve(response.data);
    })
    .catch(err => {
      reject(err)
    })
  })
}


/**
 * 封装post请求
 */

 export function post(url,data = {}){
   return new Promise((resolve,reject) => {
     axios.post(process.env.elec+url,data)
          .then(response => {
            resolve(response.data);
          },err => {
            reject(err)
          })
   })
 }
